'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    /*
      Add altering commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.createTable('users', { id: Sequelize.INTEGER });
    */
    const { INTEGER, STRING, DATE, DECIMAL, TINYINT } = Sequelize;
    await queryInterface.createTable('order_master', {
      order_id: {
        allowNull: false,
        primaryKey: true,
        type: STRING(32),
      },
      uid: {
        type: INTEGER,
        allowNull: false,
      },
      username: {
        type: STRING,
        allowNull: false,
      },
      count: {
        type: STRING,
        unsigned: false,
        allowNull: false,
      },
      start_city: {
        type: STRING(16),
        allowNull: false,
      },
      end_city: {
        type: STRING(16),
        allowNull: false,
      },
      amount: {
        type: DECIMAL(8, 2),
        unsigned: true,
      },
      pay_status: {
        type: TINYINT,
        allowNull: false,
      },
      train_num: {
        type: STRING,
        allowNull: false,
      },
      created_at: {
        allowNull: false,
        type: DATE,
      },
      updated_at: {
        allowNull: false,
        type: DATE,
      },
    }).then(() => queryInterface.addIndex('order_master', ['uid']));
  },

  down: async (queryInterface, Sequelize) => {
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */
    console.log(Sequelize);
    return await queryInterface.dropTable('order_master');
  },
};

